import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'
import { useUserStore } from '@/stores/user/index.js'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes,
})

router.beforeEach(async (to, from, next) => {
  next()
  const userStore = useUserStore()
  if (userStore.isSign && to.path == '/auth') {
    // 已登录
    // await userStore.getUserInfo()
    next({ path: '/', replace: true })
  } else {
    next()
  }
})
export default router
